from util.point_transform import *
import os

def Pic2Video(file, video_name):
    fps = 10  # 视频每秒24帧
    size = (1600, 970)  # 需要转为视频的图片的尺寸
    fourcc = cv2.VideoWriter_fourcc(*'XVID')

    list = os.listdir(file)
    # list = sorted(list, key=lambda x: os.path.getmtime(os.path.join(file, x)))
    list = sorted(list)
    img12 = cv2.imread(os.path.join(file, list[0]))
    size = (img12.shape[1],img12.shape[0])
    print(size)
    videoWriter = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), fps, size)

    for i in list:
        img12 = cv2.imread(os.path.join(file, i))
        img12 = cv2.resize(img12, size)
        videoWriter.write(img12)
    videoWriter.release()

root_path='/media/king/MyPassport0/20210403/040302/040302_continuous/'
scenes=os.listdir(root_path)
count=0
for scene in scenes:
    count+=1
    print(scene,count)
    image_path=root_path + '/' + scene + '/pic_040302_release'
    if os.path.exists(image_path):
        Pic2Video(image_path+'/p0',
                  root_path + '/' + scene +'/'+ 'p0camera.mp4')
        Pic2Video(image_path+'/p1',
                  root_path + '/' + scene +'/'+ 'p1camera.mp4')
